<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>

  // post新增
  function add() {
    let xhr = new XMLHttpRequest()
    xhr.open('post', 'http://localhost:4399/login')
    // xhr.setRequestHeader('content-Type', 'application/x-www-form-urlencoded')
    // 默认form类型
    // xhr.send('name=小白龙&age=300&sex=男&adress=东海')
    xhr.setRequestHeader('content-Type', 'application/json')
    // json
    let obj = {
      username: 'admin1',
      password: 123456
    }
    xhr.send(JSON.stringify(obj))
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        let res = JSON.parse(xhr.responseText)
        console.log(res)
      }
    }
  }
  // add()

  // 注册
  function register() {
    let xhr = new XMLHttpRequest()
    xhr.open('post', 'http://localhost:4399/register')
    // xhr.setRequestHeader('content-Type', 'application/x-www-form-urlencoded')
    // 默认form类型
    // xhr.send('name=小白龙&age=300&sex=男&adress=东海')
    xhr.setRequestHeader('content-Type', 'application/json')
    // json
    let obj = {
      username: 'admin1',
      password: 123456
    }
    xhr.send(JSON.stringify(obj))
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        let res = JSON.parse(xhr.responseText)
        console.log(res)
      }
    }
  }

  add()
</script>

</html>